package com.example.server.utils;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;

public class ElasticsearchHelper {
    @Value("${spring.elasticsearch.rest.uris}")
    private static String ip;

    public static RestHighLevelClient getConnection() {
        // 连接elasticsearch并返回连接对象
        HttpHost httpHost = new HttpHost("127.0.0.1", 9200);
        RestClientBuilder builder = RestClient.builder(httpHost);
        return new RestHighLevelClient(builder);
    }
}
